package reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
//        Teacher t = new Teacher();
//        t.name = "张三";
        Class cls = Class.forName("reflect.Teacher");
        Object obj = cls.newInstance();
        Field field = cls.getDeclaredField("name");//获取Teacher类中名为name的属性
        field.set(obj, "张麒");
        System.out.println(field.get(obj));

        Field field1 = cls.getDeclaredField("age");
        field1.setAccessible(true);
        field1.set(obj, 18);
        System.out.println(field1.get(obj));
        field1.setAccessible(false);
    }
}
